<?php
class LatihansController extends AppController {
	var $name = 'Latihans';
	
	function index() {
		$this->paginate=array('limit'=>2);
		$latihans=$this->Paginate('Latihan');
		$this->set(compact('latihans'));
		//$this->set('latihans',
		//$this->Latihan->find('all'));
	}
	
	function add() {
		if (!empty ($this->data)) {
			if ($this->Latihan->save($this->data)) {
				$this->Session->setFlash('SMS Terkirim...');
				$this->redirect(array('action' =>'index'));
			}
		}
	}
	
	function tampil($id=null) {
		$this->Latihan->id = $id;
		$this->set('latihan', $this->Latihan->read());
	}
	
	function ubah($id=null) {
		if (!$id) {
			$this->Session->setFlash('tidak ditemukan id post by simar');
			$this->redirect(array('action' =>'index'),null,true);
		}
		
		if (empty ($this->data)) {
			$this->data = $this->Latihan->find(array ('id' => $id));
		}
		
		else {
			if ($this->Latihan->save($this->data)) {
				$this->Session->setFlash('selamat data terupdate by simar');
				$this->redirect(array('action' => 'index'));
			}
			
			else {
				$this->Session->setFlash('Maaf ulangi lagi');
			}
		}
	}
	
	function delete($id=null) {
		if (!$id) {
			$this->Session->setFlash('id tidak valid by simar');
			$this->redirect(array('action' =>'index'));
		}
		
		if ($this->Latihan->delete($id)) {
			$this->Session->setFlash('Post #'.$id.'Terhapus');
			$this->redirect(array('action'=>'index'));
		}
	}
}
?>